Zig (programming Language)
   HOME

TheInfoList



OR:

Zig is an imperative, general-purpose, statically typed,
compiled In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
system programming language A system programming language is a programming language used for system programming; such languages are designed for writing system software, which usually requires different development approaches when compared with application software. Edsger W ...
designed by Andrew Kelley. The language is designed for "robustness, optimality and maintainability", supporting
compile-time In computer science, compile time (or compile-time) describes the time window during which a computer program is compiled. The term is used as an adjective to describe concepts related to the context of program compilation, as opposed to concept ...
generics,
reflection Reflection or reflexion may refer to: Science and technology * Reflection (physics), a common wave phenomenon ** Specular reflection, reflection from a smooth surface *** Mirror image, a reflection in a mirror or in water ** Signal reflection, in ...
and evaluation,
cross-compilation A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. For example, a compiler that runs on a PC but generates code that runs on an Android smartphone is a cross ...
and
manual memory management In computer science, manual memory management refers to the usage of manual instructions by the programmer to identify and deallocate unused objects, or garbage. Up until the mid-1990s, the majority of programming languages used in industry supp ...
. A major goal of the language is to improve upon the
C language C (''pronounced like the letter c'') is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities o ...
, while also taking inspiration from
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
, among others. Zig has many features for low-level programming, notably packed structs (structs without padding between fields), arbitrary-width integers and multiple pointer types. Zig is not just a new language, Zig also ships with a C/C++ compiler, and Zig can be used with either or both languages. Since version 0.10 the (new default) Zig compiler is written in Zig, i.e. it's a self-hosting compiler, and that's the major new feature of the new release (the older legacy
bootstrapping In general, bootstrapping usually refers to a self-starting process that is supposed to continue or grow without external input. Etymology Tall boots may have a tab, loop or handle at the top known as a bootstrap, allowing one to use fingers ...
compiler, written in C++, is still an option but will not be in 0.11). The default backend (i.e. the optimizer) is still LLVM (now version 15, legacy uses version 13), and LLVM is written in C++. Zig (i.e. the compiler, not generated code from it) with LLVM is 169 MiB, vs without LLVM 4.4 MiB. When compiling with the new Zig compiler much less memory is used (the older, now legacy, compiler uses 3.5x more memory), and it compiles a bit faster. Faster executable code is usually complied with the new compiler (i.e. its LLVM code generation is better), and it fixes many bugs, but there are also improvements for the older legacy compiler in version 0.10. The self-hosted linker is tightly coupled with the self-hosted compiler. The new version also adds some experimental (tier-3) support for AMD GPUs (there's also some lesser support for Nvidia GPUs and for PlayStation 4 and 5). The older bootstrapping ("stage1") compiler is written in Zig and
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
, using
LLVM LLVM is a set of compiler and toolchain technologies that can be used to develop a front end for any programming language and a back end for any instruction set architecture. LLVM is designed around a language-independent intermediate repre ...
13 as a back-end, supporting many of its native targets. The compiler is
open source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
under the
MIT License The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts only very limited restriction on reuse and has, therefore, high license comp ...
. The Zig compiler exposes the ability to compile C and C++ similarly to
Clang Clang is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages, as well as the OpenMP, OpenCL, RenderScript, CUDA, and HIP frameworks. It acts as a drop-in replacement for the GNU Compiler Collection ...
with the commands "zig cc" and "zig c++", providing many headers including
libc The C standard library or libc is the standard library for the C programming language, as specified in the ISO C standard.ISO/IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the original ANSI C standard, it was ...
and libcxx for many different platforms, allowing Zig's cc and c++ sub-commands to act as cross compilers out of the box. Plus the operating systems (mostly desktop ones) officially supported (and documented), (minimal) applications can and have been made for Android (with
Android NDK Code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) using the Android Native Development Kit (NDK). The NDK uses the Clang compiler to compile C/C++. GCC was included until NDK r17, but removed in r18 in ...
, and programming for
iOS iOS (formerly iPhone OS) is a mobile operating system created and developed by Apple Inc. exclusively for its hardware. It is the operating system that powers many of the company's mobile devices, including the iPhone; the term also include ...
also possible). Zig doesn't have its own official package manager (non-official ones exist), but a standard one has a milestone for 0.12. Zig development is funded by the Zig Software Foundation (ZSF), a non-profit corporation with Andrew Kelley as president, which takes in donations and hires multiple full-time employees.


Examples


Hello World

const std = @import("std"); pub fn main() !void


Generic linked list

pub fn main() void fn LinkedList(comptime T: type) type


Projects


Bun
is a
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
and
TypeScript TypeScript is a free and open source programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are ...
runtime written in Zig, using Safari's JavaScriptCore
virtual machine In computing, a virtual machine (VM) is the virtualization/emulation of a computer system. Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized hardw ...
.


See also

* C *
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
* Nim *
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
* D


References


External links

*
Zig on GitHubMovie: Introducing ZigMovie: The Road to 1.0Zig Weekly
{{Authority control Programming languages Cross-platform free software Cross-platform software Embedded systems Free compilers and interpreters Free computer libraries Programming languages created in 2015 Statically typed programming languages Software using the MIT license Systems programming languages C (programming language) compilers